/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hbr;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
 * Inits session factory
 * 
 */
class HibernateHelper {

    private static final Configuration cfg = new Configuration();

    static {
        buildSessionFactory();
    }

    /**
     *  Configures session factory. Hibernate automatically bounds factory
     * to JNDI name. Thouse session factory became accsessible from InitialContext
     *
     * @return SessionFactory - sessions factory, includes all of the metadata
     * about Object/Relational Mapping
     */
    private static SessionFactory buildSessionFactory() {
        try {
            return cfg.configure().buildSessionFactory();
        } catch (Throwable ex) {
            Logger.getLogger(HibernateHelper.class).fatal(ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    /**
     * Gets value of session factory properies
     * @param key - name of property described in hibernate.cfg.xml
     * @return String - value of property
     */
    public static String getPropertyValue(String key) {
        return cfg.getProperty(key);
    }
}
